<?php

namespace Common\Controller;
use Think\Controller\RestController;

Class PrettyRestController extends RestController {

    public function __construct() {
        parent::__construct();
    }

    protected function prettyResponse($status=200, $message="OK", $data=array(), $type="json") {
        
        $types = array("json", "xml");

        if (!is_int($status)) return false;
        if (!is_string($message)) return false;
        if (!is_array($data)) return false;
        if (!in_array(strtolower($type), $types)) return false;

        $responseData['status'] = $status;
        $responseData['message'] = $message;
        $responseData['content'] = $data;

        $this->response($responseData, $type);

        return true;
    }

    protected function docResponse($data) {
        
        $this->response($data, 'json');
    }
}
